/**
*登录和注册
*/

Ext.onReady(function(){
	Ext.QuickTips.init();//使用表单提示
    serverUrl = '/beautyos/index.php/';
    //定义登录表单
    var loginForm = new Ext.FormPanel({
    	labelWidth: 75,
    	baseCls: 'x-plain',
    	defaults: {width: 150},
    	defaultType: 'textfield',
        items: [{//默认字段类型
       		fieldLabel: '用户',
       		name: 'user_name',
       		anchor:'95%',
       		allowBlank:false,
       		blankText:'用户名不能为空'//错误提示内容
      	},{
	        inputType:'password',
	        fieldLabel: '密码',
	        anchor:'95%',
	        name: 'user_pass',
	        allowBlank:false,
	        blankText:'密码不能为空'
      	}],
      	buttons:[{
			text: '登录',
			type: 'submit',
     		handler:function(){ //定义表单提交事件
            	if(loginForm.form.isValid()){
            		Ext.MessageBox.show({
            			title: '请稍等',
            			msg: '正在加载...',
            			progressText: '',width:300,
            			progress:true,
            			closable:false,
            			animEl:'loading'
           });
           
          var f = function(v){//控制进度速度
          	return function(){
            	var i = v/11;
             	Ext.MessageBox.updateProgress(i, '');
             };
           };

           for(var i = 1; i < 13; i++){
          	 	setTimeout(f(i), i*150);
           }
                                 
          //提交到服务器操作
          loginForm.form.doAction('submit',{
          	url:serverUrl+'login/login',
          	method:'post',
          	params:'',
          	success:function(form,action){
            	if (action.result.msg=='ok') {
             		document.location= serverUrl;
            	} else {
             		Ext.Msg.alert('错误',action.result.msg);
            	}
          	},
         	failure:function(){
         		Ext.Msg.alert('错误','服务器出现错误请稍后再试！');
          	}
          });
         }                                       
      }
      	},{
      		text:'注册',
      		handler:function(){
      			LoginWin.hide();
      			RegisterWin.show();
      		}
      		
      	}]
    });   
          //定义窗体
	var LoginWin = new Ext.Window({
        id:'login-win',
        title:'用户登陆',
        layout:'fit',
        width:350,
        height:250,
        plain:true,
        bodyStyle:'padding:50px;',
        maximizable:false,
        closeAction:'close',
        closable:false,
        plain: true,
        buttonAlign:'center',
        items:loginForm
      });
      LoginWin.show();//显示窗体
     
     var RegisterForm = new Ext.FormPanel({
     	labelWidth: 55,
    	baseCls: 'x-plain',
    	defaultType: 'textfield',
    	frame : true,
    	items:[{
    		fieldLabel: '用户',
       		name: 'user_name',
       		anchor:'95%',
       		allowBlank:false,
       		blankText:'用户名不能为空',//错误提示内容
       		
 		},{
 			inputType:'password',
	        fieldLabel: '密码',
	        anchor:'95%',
	        name: 'user_pass',
	        allowBlank:false,
	        blankText:'密码不能为空',
	       
 		},{
 			inputType:'password',
	        fieldLabel: '确认密码',
	        anchor:'95%',
	        name: 'user_passconf',
	        allowBlank:false,
	        blankText:'密码不能为空',
	       
 		},{
 			inputType:'textfield',
	        fieldLabel: '电子邮箱',
	        anchor:'95%',
	        name: 'user_email',
	        allowBlank:false,
	        vtype:'email',
	        blankText:'邮箱不合法'
 		}],
 		buttons:[{
 			text:'好了',
 			handler:function() {
 				if(RegisterForm.form.isValid()){
 					RegisterForm.form.doAction('submit',{
          				url:serverUrl+'login/register',
          				method:'post',
          				params:'',
          				success:function(form,action){
			            	Ext.Msg.alert('错误',action.result.msg);
          				},
         				failure:function(){
         					Ext.Msg.alert('错误','服务器出现错误请稍后再试！');
          				}
          			});
 				}
 			}
 		},{
 			text:'返回登录'
 		}]
     });
     var RegisterWin = new Ext.Window({
     	id:'register-win',
     	title:'用户注册',
     	layout:'fit',
     	 width:350,
        height:250,
        plain:true,
        bodyStyle:'padding:30px;',
        maximizable:false,
        closeAction:'close',
        closable:false,
        plain: true,
        buttonAlign:'center',
        items:RegisterForm
     });
      
   
          
});